package com.etc.dao.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import com.etc.dao.UserDao;
import com.etc.entity.UserRowMapper;
import com.etc.entity.Users;

@Repository(value = "userDao")
public class UsersDaoImpl implements UserDao {

	// 从spring的容器中拿过来，直接进行注入
	@Resource
	private JdbcTemplate jdbcTemplate;

	@Override
	public Users getUsersById(int userId) {
		// TODO Auto-generated method stub
		String sql = "select userId,userName,userAge from users where userId=?";
		return jdbcTemplate.queryForObject(sql, new UserRowMapper(),userId);
	}

	@Override
	public List<Users> getUsers() {
		// TODO Auto-generated method stub
		String sql = "select userId,userName,userAge from users";
		return jdbcTemplate.query(sql, new UserRowMapper());

	}

}
